package com.travel.JPA;

import com.travel.Bean.Ticket;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface TicketJPA extends JpaRepository<Ticket,Integer> {

    @Modifying
    @Query("delete from Ticket where id in ?1")
    Integer deleteByIds(Integer[] ids);

    @Modifying
    @Query("update Ticket set enable = 1 where id in ?1")
    Integer deleteNoByIds(Integer[] ids);

    /**
     * 更新项目启用用户
     *
     * @param ticketId    项目id
     * @param enable_user 启用用户 0、可见 1、不可见
     * @return {@link Integer}
     */
    @Modifying
    @Query("update Ticket set enable_user = ?2 where id = ?1")
    Integer updateTicketEnable_user(Integer ticketId,Integer enable_user);


    @Query("select ticket_price from Ticket where id = ?1")
    Double findPriceById(Integer id);

    @Query("select ticket_name from Ticket where id = ?1")
    String findNameById(Integer id);

    /**
     * 找到景区id通过id
     *
     * @param ticketId 项目id
     * @return {@link Integer}
     */
    @Query(value = "select t.enable_user from Ticket t where t.id = ?1")
    Integer findCultureIdById(Integer ticketId);

    /**
     * 找到用户可见状态根据id
     *
     * @param ticketId 项目id
     * @return {@link Integer}
     */
    @Query(value = "select t.enable_user from ticket t where t.id = ?1",nativeQuery = true)
    Integer findEnable_userById(Integer ticketId);
}
